MkHtmlTable
Class representing a html table.¶
Description
Compared to MkTable, this will end up with a more verbose output, but it can contain more complex Markdown in cells.
Example: Regular¶
Jinja
{% set code_col = [_mk.MkCode("print('hello world')
sys.exit()"), _mk.MkCode("print('hello world')
sys.exit()")] %}
{% set admonitions = [_mk.MkAdmonition("Admonition inside cell"), _mk.MkAdmonition("Admonition inside cell")] %}
{% set tabs = [_mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"])), _mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"]))] %}
{% set data = {"Code": code_col, "Admonitions": admonitions, "Tabs": tabs} %}
{{ data | MkHtmlTable }}
Python
Code | Admonitions | Tabs |
Info Admonition inside cell |
Tab a Tab b |
|
Info Admonition inside cell |
Tab a Tab b |
<table markdown="1">
<tr>
<td>
Code
</td>
<td>
Admonitions
</td>
<td>
Tabs
</td>
</tr>
<tr>
<td>
```` {.python }
print('hello world')
sys.exit()
````
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
<tr>
<td>
```` {.python }
print('hello world')
sys.exit()
````
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
</table>
<table>
<tr>
<td>
Code
</td>
<td>
Admonitions
</td>
<td>
Tabs
</td>
</tr>
<tr>
<td>
<div class="language-python highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="nb">print</span><span class="p">(</span><span class="s1">'hello world'</span><span class="p">)</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span>
</span></code></pre></div>
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
<tr>
<td>
<div class="language-python highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="nb">print</span><span class="p">(</span><span class="s1">'hello world'</span><span class="p">)</span>
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span>
</span></code></pre></div>
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
</table>
MkHtmlTable
├── MkCode("print('hello world')\nsys.exit()")
│ ╰── MkText("print('hello world')\nsys.exit()")
├── MkCode("print('hello world')\nsys.exit()")
│ ╰── MkText("print('hello world')\nsys.exit()")
├── MkAdmonition('Admonition inside cell')
│ ╰── MkText('Admonition inside cell')
├── MkAdmonition('Admonition inside cell')
│ ╰── MkText('Admonition inside cell')
├── MkTabbed(tabs=[...])
│ ├── MkTab(title='A', content='Tab a', new=True)
│ │ ╰── MkText('Tab a')
│ ╰── MkTab(title='B', content='Tab b')
│ ╰── MkText('Tab b')
├── MkTabbed(tabs=[...])
│ ├── MkTab(title='A', content='Tab a', new=True)
│ │ ╰── MkText('Tab a')
│ ╰── MkTab(title='B', content='Tab b')
│ ╰── MkText('Tab b')
Name | Children | Inherits |
---|---|---|
MkBaseTable mknodes.basenodes.mkbasetable Base Class for MkTables. Only deals with managing the data. |
graph TD
94721312779728["mkhtmltable.MkHtmlTable"]
94721311951440["mkbasetable.MkBaseTable"]
94721311697232["mkcontainer.MkContainer"]
94721308848336["mknode.MkNode"]
94721311766592["node.Node"]
140564252373184["builtins.object"]
94721311951440 --> 94721312779728
94721311697232 --> 94721311951440
94721308848336 --> 94721311697232
94721311766592 --> 94721308848336
140564252373184 --> 94721311766592
/home/runner/work/mknodes/mknodes/mknodes/basenodes/mkhtmltable/metadata.toml
[metadata]
icon = "octicon:table-24"
status = "new"
name = "MkHtmlTable"
[examples.regular]
title = "Regular"
jinja = """
{% set code_col = [_mk.MkCode("print('hello world')\nsys.exit()"), _mk.MkCode("print('hello world')\nsys.exit()")] %}
{% set admonitions = [_mk.MkAdmonition("Admonition inside cell"), _mk.MkAdmonition("Admonition inside cell")] %}
{% set tabs = [_mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"])), _mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"]))] %}
{% set data = {"Code": code_col, "Admonitions": admonitions, "Tabs": tabs} %}
{{ data | MkHtmlTable }}
"""
[output.markdown]
template = """
{% set table = node.data %}
<table markdown="1">
<tr>
{% for header in table.keys() %}
<td>
{{ header }}
</td>
{% endfor %}
</tr>
{% for row in node.iter_rows() %}
<tr>
{% for item in row %}
<td>
{{ item }}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
"""